package com.atl.controller.wx.admin;

import com.atl.common.BaseContext;
import com.atl.common.BaseResponse;
import com.atl.common.DeleteRequest;
import com.atl.enity.po.ChargingStations;
import com.atl.enity.po.StockUser;
import com.atl.enity.wx.admin.vo.ChargingStationsDetailsListVO;
import com.atl.enity.wx.admin.vo.ChargingStationsList2VO;
import com.atl.enity.wx.admin.vo.ChargingStationsListVO;
import com.atl.enity.wx.admin.vo.StockUserListVO;
import com.atl.execption.BusinessException;
import com.atl.service.IChargingStationsService;
import com.atl.service.IStockUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 临晖
 * @since: 2024-06-26
 */
@RestController
@RequestMapping("/wx/admin/charging-stations")
@Slf4j
@Api(tags = "电桩信息")
public class WXChargingStationsController {

    @Resource
    private IChargingStationsService chargingStationsService;

    /**
     * 查询
     *
     * @param request
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("电桩信息")
    public BaseResponse<List<ChargingStationsListVO>> search1(HttpServletRequest request) {
        List<ChargingStations> list = chargingStationsService.lambdaQuery()
                .eq(ChargingStations::getAgentUserId, BaseContext.getId())
                .list();

        List<ChargingStationsListVO> res = list.stream()
                .map(obj -> {
                    ChargingStationsListVO listVO = new ChargingStationsListVO();
                    BeanUtils.copyProperties(obj, listVO);
                    return listVO;
                }).collect(Collectors.toList());
        return BaseResponse.okResult(res);
    }


    /**
     *
     *
     * @param request
     * @return
     */
    @PostMapping("/manngerlist")
    @ApiOperation("电桩管理")
    public BaseResponse<List<ChargingStationsList2VO>> search2( HttpServletRequest request) {
        List<ChargingStations> list = chargingStationsService.lambdaQuery()
                .eq(ChargingStations::getAgentUserId, BaseContext.getId())
                .list();

        List<ChargingStationsList2VO> res = list.stream()
                .map(obj -> {
                    ChargingStationsList2VO listVO = new ChargingStationsList2VO();
                    BeanUtils.copyProperties(obj, listVO);
                    return listVO;
                }).collect(Collectors.toList());
        return BaseResponse.okResult(res);
    }


    /**
     *
     * 修改
     *
     * @param chargingStations
     * @param request
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("电桩编辑")
    public BaseResponse update(ChargingStations chargingStations, HttpServletRequest request) {

        if (chargingStations.getId() <= 0) {
            throw new BusinessException(-1, "id为空");
        }

        boolean res = chargingStationsService.updateById(chargingStations);
        return BaseResponse.okResult(res);
    }


    /**
     * 根据id查询电桩信息
     *
     * @param deleteRequest
     * @param request
     * @return
     */
    @PostMapping("/details")
    @ApiOperation("电桩信息详情")
    public BaseResponse<ChargingStations> getById(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {

        if (deleteRequest == null || deleteRequest.getId() <= 0) {
            throw new BusinessException(-1, "id为空");
        }

        ChargingStations one = chargingStationsService.getById(deleteRequest.getId());

        //ChargingStationsDetailsListVO vo = new ChargingStationsDetailsListVO();
        //BeanUtils.copyProperties(one, vo);
        return BaseResponse.okResult(one);
    }

}
